package at.ac.tuwien.swa.sparrow.web

import at.ac.tuwien.swa.sparrow.server.component.PeerManager
import at.ac.tuwien.swa.sparrow.server.persistence.{SongRecognitionRepository, AccountRepository}
import javax.inject.Inject
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{ResponseBody, RequestMapping}

@Controller
@RequestMapping(Array("/administration"))
class AdminController @Inject()(accountRepository: AccountRepository, peerManager: PeerManager, songRepo: SongRecognitionRepository) {
	@RequestMapping(Array("/users"))
	@ResponseBody def users() = accountRepository.findAll().toList.sortBy(_.username)

	@RequestMapping(Array("/peers"))
	@ResponseBody def peers() = peerManager.onlinePeers.toList.sortBy(_.account.username)

	@RequestMapping(Array("/stream"))
	@ResponseBody def stream() = (songRepo findAll()).toList.sortBy(-_.time) take 10
}
